package com.igbeok.miscellaneous.concurrency.thij;

public class WaitPerson extends Thread {
	private Restaurant restaurant;

	public WaitPerson(Restaurant r) {
		this.restaurant = r;
	}

	public void run() {
		while (true) {
			while (restaurant.order == null) {
				synchronized (this) {
					try {
						System.out.println(this + ": Order没有了, 正在等待Order....");
						wait();
					} catch (InterruptedException e) {
						throw new RuntimeException(e);
					}
				}
			}
			System.out.println(this + ": Waitperson得到了 " + restaurant.order);
			restaurant.order = null;
		}
	}
}
